import { getSellers, addSeller, updateSeller, disableSeller, ableSeller } from '@/api/seller'


const state = {
  sellers: []
}

const mutations = {
  GET_ALL_SELLERS: (state, new_sellers_data) => {
    state.sellers = new_sellers_data
  },
  NULL: () => { }
}

const actions = {
  //分页获取全部销售
  getAllSellers ({ commit }, { page, pageSize }) {
    return new Promise((resolve, reject) => {
      getSellers({ page, pageSize }).then(response => {
        if (response) {
          commit('GET_ALL_SELLERS', response.data.records)
        }
        resolve(response)
      }).catch(error => {
        reject(error)
      })
    })
  },
  //添加销售
  add ({ commit }, user) {
    return new Promise((resolve, reject) => {
      addSeller(user).then(response => {
        resolve(response)
      }).catch(error => {
        reject(error)
      })
    })
  },
  //修改销售
  update ({ commit }, user) {
    return new Promise((resolve, reject) => {
      updateSeller(user).then(response => {
        resolve(response)
      }).catch(error => {
        reject(error)
      })
    })
  },
  //禁用销售
  disable ({ commit }, ids) {
    return new Promise((resolve, reject) => {
      disableSeller(ids).then(response => {
        resolve(response)
      }).catch(error => {
        reject(error)
      })
    })
  },
  //启用销售
  able ({ commit }, ids) {
    return new Promise((resolve, reject) => {
      console.log(ids);
      ableSeller(ids).then(response => {
        resolve(response)
      }).catch(error => {
        reject(error)
      })
    })
  },
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}